package MAIN;

import java.util.Scanner;

public class Main2 {
    //求最大连续子数组的和
    public static int sumArr(int[] arr) {
        int[] arr2 = new int[100000];
        int i = 0;
        int j = 1;
        while (i < arr.length -1 && j < arr.length - 1 &&
                arr[i] + 1 == arr[j]) {
            arr2[i++] = arr[i];
            arr2[i++] = arr[j++];
        }
        int sum2 = 0;
        for (int k = 0; k < arr2.length - 1; k++) {
            sum2 += arr2[k];
        }
        return sum2;
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {// 注意，如果输入是多个测试用例，请通过while循环处理多个测试用例
            int a = in.nextInt();
            int[] array = null;
            for (int i = 0; i < a; i++) {
                Scanner scanner = new Scanner(System.in);
                array = new int[a];
                for (int j = 0; j < array.length - 1; j++) {
                    array[j] = scanner.nextInt();
                }
            }
            int sum = sumArr(array);
            System.out.println(sum);
        }
    }
    //把一个字符串B加入到字符串A中，看构成回文字符串的方式有几种？
    public static int func(String s1,String s2) {
        if (isCycle(s1) || isCycle(s2)) return 0;
        int count = 0;
        StringBuilder sb1 = new StringBuilder(s1);
        StringBuilder sb2 = new StringBuilder(s2);
        for (int i = 0; i < sb1.length(); i++) {
            sb1.append(sb2);
            if (isCycle(sb1.toString())) {
                count++;
            }
            int flg = 1;
            while (flg <= sb1.length()-1) {
                String s3 = sb1.toString().substring(0, sb1.length()-flg);
                if (isCycle(sb1.toString())) {
                    count++;
                }
                flg++;
                StringBuilder sb3 = new StringBuilder(s3);
                sb3.append(sb2);
            }
        }
        return count;
    }
    private static boolean isCycle(String str) {
        int j = 0;
        int k = str.length() - 1;
        char ch1 = str.charAt(j);
        char ch2 = str.charAt(k);
        while (j <= k) {
            if (ch1 == ch2) {
                j++;
                k--;
            } else {
                return false;
            }
        }
        return true;
    }
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {// 注意，如果输入是多个测试用例，请通过while循环处理多个测试用例
            String a = in.next();
            String b = in.next();
            int count = func(a,b);
            System.out.println(count);
        }
    }
}
